/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#include "Drawing.hpp"
tex font; // Static Texture for our font //
bool NICE = false; // Bool value to set if it should draw nicely or not //
int Width = 64; // Our Width and height //
int Height = 32;
#ifdef WIN32
	#include <io.h>
	#define strcasecmp _stricmp
	#define strncasecmp _strnicmp
	char *strsep ( char ** stringp, const char *delim )
	{
		char *p;

		if (!stringp)
		    return (NULL);

		p = *stringp;

		while (** stringp && !strchr(delim, ** stringp))
		    (*stringp)++;

		if (** stringp)
		{
		    ** stringp = '\0';
		    (*stringp)++;
		}
		else
		    *stringp = NULL;
		return (p);
	}
	#define EXPORT __declspec (dllexport)
#else
	#define EXPORT
#endif
int InitScreen(int _Width, int _Height) // This May need to be cleaned up a bit //
{
	Width = _Width;
	Height = _Height;
	// Initialize SDL's subsystems - in this case, only video.
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 
	{
		printf("Unable to init SDL: %s\n", SDL_GetError());
		exit(1);
	}
	// Register SDL_Quit to be called at exit; makes sure things are
	// cleaned up when we quit.
	atexit(SDL_Quit);
	
	SDL_WM_SetCaption("Veni-Venchi", NULL);
	SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	if(!SDL_SetVideoMode(_Width, _Height, 24, SDL_OPENGL/* | SDL_FULLSCREEN*/))
	{
		/* Error occurred */
		printf("Error! %s\n", SDL_GetError());
		return false;
	}
	if(NICE)
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 16);
	else
		SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
	
    glEnable(GL_BLEND);
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);
    glShadeModel(GL_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDepthFunc(GL_LEQUAL);  // Type Of Depth Testing
    glEnable(GL_DEPTH_TEST); // Enable Depth Testing
    glAlphaFunc(GL_NOTEQUAL, 0.0);
    if(NICE)
    {
		glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
		glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
		glEnable(GL_POINT_SMOOTH);
		glEnable(GL_LINE_SMOOTH);
		glEnable(GL_POLYGON_SMOOTH);
    }
    else
    {
    	glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
		glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
		glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
		glDisable(GL_POINT_SMOOTH);
		glDisable(GL_LINE_SMOOTH);
		glDisable(GL_POLYGON_SMOOTH);
    }
	// Set OpenGL viewport
	glViewport(0, 0, _Width, _Height);
	
	// Set OpenGL projection
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0, _Width, _Height, 0.0, -1.0, 1.0);
	
	font = LoadTexture("Data/Font.png", 0, 0, 0);
	SDL_ShowCursor(1);
	glClearColor(0.75f,0.75f,0.75f,0.0f);
	if ( SDL_Init(SDL_INIT_TIMER) < 0 ) 
	{
		printf("Unable to init SDL: %s\n", SDL_GetError());
		exit(1);
	}
	return true;
}
void DrawChar( int x, int y, int z, char chr, int ww, int hh, float r, float g, float b, float a) // Puts a single character on screen //
{
	glBindTexture(GL_TEXTURE_2D, font.Tex);
	glPushMatrix();
	glTranslatef(x, y, z); // move center of quad back to where it was
	glBegin(GL_QUADS);
	glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
	float w=font.Width;

	if((chr-32)*8 >= 472)
		chr=chr-32;
	float ch = float(chr-32);
		glTexCoord2f(((ch*8.0f)/w),0.0f);
		glVertex3i(0, 0, z);

		glTexCoord2f(((ch*8.0f)+8.0f)/w, 0.0f);
		glVertex3i(0 + ww, 0, z);

		glTexCoord2f(((ch*8.0f)+8.0f)/w, 1.0f);
		glVertex3i(0 + ww, 0 + hh, z);

		glTexCoord2f((ch*8.0f)/w, 1.0f);
		glVertex3i(0, 0 + hh, z);
		glColor4f(1.0f,1.0f,1.0f,1.0f);
	glEnd();
	glPopMatrix();
}
void DrawChar( int x, int y, char chr, int ww, int hh, float r, float g, float b, float a) // Puts a single character on screen //
{
	DrawChar(x, y, 0, chr, ww, hh, r, g ,b ,a );
}
void DrawStringCenter(int x, int y, const std::string string, int w, int h, float r, float g, float b, float a)
{
	int offsetx = w * strlen(string.c_str()) / 2;
	int offsety = h * strlen(string.c_str()) / 2;
	DrawString(x - offsetx, y - offsety, string, w, h, r, g, b, a);
}
void DrawStringCenter(int x, int y, const char *string, int w, int h, float r, float g, float b, float a)
{
	int offsetx = w * strlen(string) / 2;
	int offsety = h * strlen(string) / 2;
	DrawString(x - offsetx, y - offsety, string, w, h, r, g, b, a);
}
void DrawString(int x, int y, const std::string string, int w, int h, float r, float g, float b, float a) //Draws using std string
{
	DrawString(x,y,string.c_str(),w,h,r,g,b,a); // Just calls the other one, very easy
}
void DrawString(int x, int y, const int string, int w, int h, float r, float g, float b, float a)
{
	char temp[64]; // If you need more than 64 characters in a int, wtf are you doing?
	sprintf(temp, "%d", string);
	DrawString(x,y,temp,w,h,r,g,b,a);
}
void DrawString(int x, int y, const char *string, int w, int h, float r, float g, float b, float a) // Draws an entire string, should probably be cleaned up...
{
char *s = (char*)malloc(strlen(string) + 1);
strcpy(s, string);
int Counter = strlen(string);
while (*s != 0 || Counter-- < 0)
{
switch(*s) {
	case (32):
		//x+=w;
		//s++;
	break;
	case ('^'):
		s++;
		switch(*s){
			case ('R'):
				r=255.0f;
				g=0.0f;
				b=0.0f;
				a=255.0f;
			break;
			case ('r'):
				r=127.5f;
				g=0.0f;
				b=0.0f;
				a=255.0f;
			break;
			case ('B'):
				r=0.0f;
				g=0.0f;
				b=255.0f;
				a=255.0f;
			break;
			case ('b'):
				r=0.0f;
				g=0.0f;
				b=127.5f;
				a=255.0f;
			break;
			case ('W'):
				r=255.0f;
				g=255.0f;
				b=255.0f;
				a=255.0f;
			break;
			case ('w'):
				r=127.5f;
				g=127.5f;
				b=127.5f;
				a=255.0f;
			break;
			case ('N'):
				r=0.0f;
				g=0.0f;
				b=0.0f;
				a=255.0f;
			break;
			case ('Y'):
				r=255.0f;
				g=255.0f;
				b=0.0f;
				a=255.0f;
			break;
			case ('y'):
				r=127.5f;
				g=127.5f;
				b=0.0f;
				a=255.0f;
			break;
			case ('P'):
				r=255.0f;
				g=0.0f;
				b=255.0f;
				a=255.0f;
			break;
			case ('p'):
				r=127.5f;
				g=0.0f;
				b=127.5f;
				a=255.0f;
			break;
			case ('C'):
				r=0.0f;
				g=255.0f;
				b=255.0f;
				a=255.0f;
			break;
			case ('c'):
				r=0.0f;
				g=127.5f;
				b=127.5f;
				a=255.0f;
			break;
			default:
				
			break;
		}
		s++;
		//x+=w;
	break;
}
	DrawChar( x, y, *s, w, h, r, g, b, a);
//drawcharacter(x, y, *s);
x+=w;
s++;
}
}
const float DEG2RAD = 3.14159/180;
void DrawCircle(float x, float y, int radius, float r, float g, float b, float a) // Draws a hollow circle
{
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D, 0);
	glLineWidth (1);
	glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
	glBegin(GL_LINE_LOOP);
 
	for (int i=0; i < 360; i++)
	{
		float degInRad = i*DEG2RAD;
		glVertex2f(x + cos(degInRad)*(radius),y + sin(degInRad)*(radius));
	}
 
	glEnd();
	glPopMatrix();
}
void DrawBoxCenter(int x, int y, int width, int height, int r,int g, int b, int a) // Draws a Hollow Box and centers it on x, y
{
	DrawBox(x - width/2, y - height/2,x + width/2, y + height/2, r, g, b, a);
}
void DrawBox(int x, int y, int ex, int ey, int r,int g, int b, int a) // Draws a Hollow Box
{
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D, 0);
	glLineWidth (1);
	glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
	glBegin(GL_LINE_LOOP);
	glVertex2f(x,y);
	glVertex2f(ex,y);
	glVertex2f(ex,ey);
	glVertex2f(x,ey);

	glEnd();
	glPopMatrix();
}
void DrawPixel(int x, int y, int r,int g,int b, int a){ // Draws a single pixel
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D, 0);
	glBegin (GL_POINTS);
	glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
    glVertex2f (x, y + 1);
	glEnd ();
	glPopMatrix();	
}

void DrawRect(int x, int y, int ex, int ey, unsigned int RGBA)
{
	union uColor
	{
		struct {
			unsigned Red	: 8;
			unsigned Green	: 8;
			unsigned Blue	: 8;
			unsigned Alpha	: 8;
		};
		unsigned int RGBA;
	};
	uColor Color;
	Color.RGBA = RGBA;
	DrawRect(x,y, ex, ey, Color.Red, Color.Green, Color.Blue, Color.Alpha);
	// Could have just done masking, but this looks nicer
}

void DrawRect(int x, int y, int ex, int ey, int r,int g, int b, int a){ // Draws a filled rect
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D, 0);
	glBegin(GL_QUADS);
	glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
		glVertex3i(x, y, 0);

		glVertex3i(ex, y, 0);

		glVertex3i(ex, ey, 0);

		glVertex3i(x, ey, 0);
	glEnd ();
	glPopMatrix();	  
}
void BeginLine(float x, float y, int r, int g,int b,int a)
{
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D, 0);
	glLineWidth (1);
	glBegin (GL_LINES);
	glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
    glVertex2f (x, y);
}
void EndLine(float x, float y)
{
	glVertex2f (x, y);
	glEnd ();
	glPopMatrix();	
}
void DrawLine(float x,float y, float xx, float yy, int r,int g, int b, int a) // a single line
{
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D, 0);
	glLineWidth (1);
	glBegin (GL_LINES);
	glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
    glVertex2f ((x), (y));
    glVertex2f ((xx), (yy));
	glEnd ();
	glPopMatrix();	
}
void DrawLine(float x,float y, float xx, float yy, int widthofline, int r,int g, int b, int a) // Can draw a line with a set width
{
	glPushMatrix();
	glBindTexture(GL_TEXTURE_2D, 0);
	glLineWidth (widthofline);
	glBegin (GL_LINES);
	glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
    glVertex2f ((x), (y));
    glVertex2f ((xx), (yy));
	glEnd ();
	glPopMatrix();	
}
void DrawPic(int x, int y, int w, int h, tex tmp){ // This will draw a texture
	glDisable(GL_POLYGON_SMOOTH);
		glPushMatrix();
		glColor4f(1.0f,1.0f,1.0f,1.0f);
		glBindTexture(GL_TEXTURE_2D, tmp.Tex);;
			glBegin(GL_QUADS);

				glTexCoord2f(0, 0.0);
				glVertex3i(x, y, 0);

				glTexCoord2f(1, 0.0);
				glVertex3i(x + w, y, 0);

				glTexCoord2f(1, 1.0);
				glVertex3i(x + w, y + h, 0);

				glTexCoord2f(0, 1.0);
				glVertex3i(x, y + h, 0);

			glEnd();
		glPopMatrix();
	glEnable(GL_POLYGON_SMOOTH);   
}
void DrawPic(float x, float y, float sx, float sy, float ex, float ey, float r, float g, float b, float a,int rr, tex tmp){ // This is an advanced form of DrawPic, able to set the starting point and end points within the texture
	glBindTexture(GL_TEXTURE_2D, tmp.Tex);
	glPushMatrix();
		glTranslatef(x+((ex-sx)/2), y+((ey-sy)/2), 0); // move center of quad back to where it was
		glRotatef(rr, 0, 0, 1); // rotate around origin (also now center of quad)
		glTranslatef(-((ex-sx)/2), -((ey-sy)/2), 0); // move center of quad to origin
		glBegin(GL_QUADS);
		
			glColor4f(r/255.0f,g/255.0f,b/255.0f,a/255.0f);
			glTexCoord2f((sx/tmp.Width), (sy/tmp.Height));
			glVertex2f(0, 0);

			glTexCoord2f((ex/tmp.Width), (sy/tmp.Height));
			glVertex2f(ex-sx, 0);

			glTexCoord2f((ex/tmp.Width), (ey/tmp.Height));
			glVertex2f(ex-sx, ey-sy);

			glTexCoord2f((sx/tmp.Width), (ey/tmp.Height));
			glVertex2f(0, ey-sy);
		glEnd();
	glPopMatrix();  
}
void DrawPicS(float x, float y, float sx, float sy, float ex, float ey,float ww,float hh,int aa, tex tmp){//TODO: Fix, Doesn't work
	glBindTexture(GL_TEXTURE_2D, tmp.Tex);
	glPushMatrix();
	//glTranslatef(x+((ex-sx)/2), y+((ey-sy)/2), 0); // move center of quad back to where it was
	glBegin(GL_QUADS);
	glColor4f(1.0f,1.0f,1.0f,aa/255.0f);
		glTexCoord2f((sx/tmp.Width), (sy/tmp.Height));
		glVertex2f(x, y);

		glTexCoord2f((ex/tmp.Width), (sy/tmp.Height));
		glVertex2f(ww+x, y);

		glTexCoord2f((ex/tmp.Width), (ey/tmp.Height));
		glVertex2f(ww+x, hh+y);

		glTexCoord2f((sx/tmp.Width), (ey/tmp.Height));
		glVertex2f(x, hh+y);
	glEnd();
	glPopMatrix();  
}
void DrawPicSR(float x, float y, float sx, float sy, float ex, float ey,float ww,float hh,int aa, tex tmp){//TODO: Fix, Doesn't work
	glBindTexture(GL_TEXTURE_2D, tmp.Tex);
	glPushMatrix();
	//glTranslatef(x+((ex-sx)/2), y+((ey-sy)/2), 0); // move center of quad back to where it was
	glBegin(GL_QUADS);
	glColor4f(1.0f,1.0f,1.0f,aa/255.0f);
		glTexCoord2f((ex/tmp.Width), (sy/tmp.Height));
		glVertex2f(x, y);

		glTexCoord2f((sx/tmp.Width), (sy/tmp.Height));		
		glVertex2f(ww+x, y);
		
		glTexCoord2f((sx/tmp.Width), (ey/tmp.Height));
		glVertex2f(ww+x, hh+y);

		glTexCoord2f((ex/tmp.Width), (ey/tmp.Height));		
		glVertex2f(x, hh+y);
	glEnd();
	glPopMatrix();   
}
tex LoadTexture(const char *filename)
{
	return LoadTexture(filename, 255, 0 , 255);
}
void pngSetStencil(const int r, const int g, const int b)
{
}

int LoadPNG(const char *filename, tex *Texture)
{
	FILE         *infile;         /* PNG file pointer */
	png_structp   png_ptr;        /* internally used by libpng */
	png_infop     info_ptr;       /* user requested transforms */
	
	char         *image_data;      /* raw png image data */
	char         sig[8];           /* PNG signature array */
	/*char         **row_pointers;   */
	
	int           bit_depth;
	int           color_type;
	
	unsigned long width;            /* PNG image width in pixels */
	unsigned long height;           /* PNG image height in pixels */
	unsigned int rowbytes;         /* raw bytes at row n in image */
	
	image_data = NULL;
	int i;
	png_bytepp row_pointers = NULL;
	
	/* Open the file. */
	infile = fopen(filename, "rb");
	if (!infile) {
		return 0;
	}
	
	
	/*
	 * 		13.3 readpng_init()
	 */
	
	/* Check for the 8-byte signature */
	fread(sig, 1, 8, infile);
	
	if (!png_check_sig((unsigned char *) sig, 8)) {
		fclose(infile);
		return 0;
	}
	
	/* 
	 * Set up the PNG structs 
	 */
	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if (!png_ptr) {
		fclose(infile);
		return 4;    /* out of memory */
	}
	
	info_ptr = png_create_info_struct(png_ptr);
	if (!info_ptr) {
		png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
		fclose(infile);
		return 4;    /* out of memory */
	}
	
	
	/*
	 * block to handle libpng errors, 
	 * then check whether the PNG file had a bKGD chunk
	 */
	if (setjmp(png_jmpbuf(png_ptr))) {
		png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
		fclose(infile);
		return 0;
	}
	
	/* 
	 * takes our file stream pointer (infile) and 
	 * stores it in the png_ptr struct for later use.
	 */
	/* png_ptr->io_ptr = (png_voidp)infile;*/
	png_init_io(png_ptr, infile);
	
	/*
	 * lets libpng know that we already checked the 8 
	 * signature bytes, so it should not expect to find 
	 * them at the current file pointer location
	 */
	png_set_sig_bytes(png_ptr, 8);
	
	/* Read the image */
	
	/*
	 * reads and processes not only the PNG file's IHDR chunk 
	 * but also any other chunks up to the first IDAT 
	 * (i.e., everything before the image data).
	 */
	
	/* read all the info up to the image data  */
	png_read_info(png_ptr, info_ptr);
	
	png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, 
				 &color_type, NULL, NULL, NULL);
	
	Texture->Width = width;
	Texture->Height = height;
	
	/* Set up some transforms. */
	if (color_type & PNG_COLOR_MASK_ALPHA) {
		png_set_strip_alpha(png_ptr);
	}
	if (bit_depth > 8) {
		png_set_strip_16(png_ptr);
	}
	if (color_type == PNG_COLOR_TYPE_GRAY ||
		color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
		png_set_gray_to_rgb(png_ptr);
	}
	if (color_type == PNG_COLOR_TYPE_PALETTE) {
		png_set_palette_to_rgb(png_ptr);
	}
	
	/* Update the png info struct.*/
	png_read_update_info(png_ptr, info_ptr);
	
	/* Rowsize in bytes. */
	rowbytes = png_get_rowbytes(png_ptr, info_ptr);
	
	
	/* Allocate the image_data buffer. */
	if ((image_data = (char *) malloc(rowbytes * height))==NULL) {
		png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
		return 4;
    }
	
	if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {
        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
        free(image_data);
        image_data = NULL;
        return 4;
    }
	
	
    /* set the individual row_pointers to point at the correct offsets */
	
    for (i = 0;  i < height;  ++i)
        row_pointers[height - 1 - i] = (png_byte*)(image_data + i*rowbytes);
	
	
    /* now we can go ahead and just read the whole image */
    png_read_image(png_ptr, row_pointers);
	
    /* and we're done!  (png_read_end() can be omitted if no processing of
     * post-IDAT text/time/etc. is desired) */
	
	/* Clean up. */
	free(row_pointers);
	
	/* Clean up. */
	png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
	fclose(infile);
	
	glGenTextures(1, &Texture->Tex);
	
	printf("(loadTexture) width: %d height: %d\n", width, height); 
	
	/* create a new texture object
	 * and bind it to texname (unsigned integer > 0)
	 */
	glBindTexture(GL_TEXTURE_2D, Texture->Tex);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, 
				 GL_RGB, GL_UNSIGNED_BYTE, image_data);
	
		
}
tex LoadTexture(const char *filename, const int r, const int g, const int b)
{
	//Simple Load texture, will set the transparency as the one in stencil
	tex TempTex;
	pngSetStencil(r,g,b);
	TempTex.LoadType = 0;
	TempTex.R = r;
	TempTex.G = g;
	TempTex.B = b;
	LoadPNG(filename, &TempTex);
	//TempTex.Tex = pngBind(filename, PNG_NOMIPMAP, PNG_STENCIL, &TempTex.Info, GL_CLAMP, GL_NEAREST, GL_NEAREST);
	if(!TempTex.Tex)
		printf("Couldn't Open %s\n", filename);
	strcpy(TempTex.Filename, filename);
	printf("aspect is %d\n", TempTex.Width/TempTex.Height);
	return TempTex;
}
tex LoadTextureA(const char *filename)
{
	//Simple Load texture, will set the transparency as the one in stencil
	tex TempTex;
	TempTex.LoadType = 1;
	LoadPNG(filename, &TempTex);
	//TempTex.Tex = pngBind(filename, PNG_NOMIPMAP, PNG_ALPHA, &TempTex.Info, GL_CLAMP, GL_NEAREST, GL_NEAREST);
	if(!TempTex.Tex)
		printf("Couldn't Open %s\n", filename);
	strcpy(TempTex.Filename, filename);
	return TempTex;
}
void ClearScreen()//Simple, clears the screen
{
	glClear(GL_COLOR_BUFFER_BIT);
	glClear(GL_DEPTH_BUFFER_BIT);
}
void Swap() // Swaps buffers
{
	SDL_GL_SwapBuffers();
}
